package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import com.example.project.entity.Company;

/**
 * 公司Mapper接口
 * 
 * @author ruoyi
 * @date 2025-09-18
 */
@Mapper
public interface CompanyMapper {

	/**
	 * 查询公司
	 * 
	 * @param id 公司主键
	 * @return 公司
	 */
	@Select("select id, project_id, company_name, company_url, merchant_name, account, estim_price, actual_price from t_company where del_flag = 0 and id = #{id}")
	public Company selectCompanyById(Long id);

	/**
	 * 查询公司列表
	 * 
	 * @param tCompany 公司
	 * @return 公司集合
	 */
	@Select("<script>select id, project_id, company_name, company_url, merchant_name, account, estim_price, actual_price from t_company where del_flag = 0 "
			+ "<if test=\"projectId != null\"> and project_id = #{projectId}</if>"
			+ "<if test=\"companyName != null and companyName != ''\"> and company_name like concat('%', #{companyName}, '%')</if>"
			+ "<if test=\"companyUrl != null and companyUrl != ''\"> and company_url = #{companyUrl}</if>"
			+ "<if test=\"merchantName != null and merchantName != ''\"> and merchant_name like concat('%', #{merchantName}, '%')</if>"
			+ "<if test=\"account != null and account != ''\"> and account = #{account}</if>"
			+ "<if test=\"estimPrice != null and estimPrice != ''\"> and estim_price = #{estimPrice}</if>"
			+ "<if test=\"actualPrice != null and actualPrice != ''\"> and actual_price = #{actualPrice}</if>"
			+ "</script>")
	public List<Company> selectCompanyList(Company tCompany);

	/**
	 * 新增公司
	 * 
	 * @param tCompany 公司
	 * @return 结果
	 */
	@Insert("<script>insert into t_company"
			+ "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">"
			+ "<if test=\"projectId != null\">project_id,</if>"
			+ "<if test=\"companyName != null\">company_name,</if>"
			+ "<if test=\"companyUrl != null\">company_url,</if>"
			+ "<if test=\"merchantName != null\">merchant_name,</if>"
			+ "<if test=\"account != null\">account,</if>"
			+ "<if test=\"estimPrice != null\">estim_price,</if>"
			+ "<if test=\"actualPrice != null\">actual_price,</if>"
			+ "del_flag,"
			+ "<if test=\"createBy != null\">create_by,</if>"
			+ "<if test=\"createTime != null\">create_time,</if>"
			+ "</trim>"
			+ "<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">"
			+ "<if test=\"projectId != null\">#{projectId},</if>"
			+ "<if test=\"companyName != null\">#{companyName},</if>"
			+ "<if test=\"companyUrl != null\">#{companyUrl},</if>"
			+ "<if test=\"merchantName != null\">#{merchantName},</if>"
			+ "<if test=\"account != null\">#{account},</if>"
			+ "<if test=\"estimPrice != null\">#{estimPrice},</if>"
			+ "<if test=\"actualPrice != null\">#{actualPrice},</if>"
			+ "0,"
			+ "<if test=\"createBy != null\">#{createBy},</if>"
			+ "<if test=\"createTime != null\">#{createTime},</if>"
			+ "</trim></script>")
	public int insertCompany(Company tCompany);

	/**
	 * 修改公司
	 * 
	 * @param tCompany 公司
	 * @return 结果
	 */
	@Update("<script>update t_company"
			+ "<trim prefix=\"SET\" suffixOverrides=\",\">"
			+ "<if test=\"projectId != null\">project_id = #{projectId},</if>"
			+ "<if test=\"companyName != null\">company_name = #{companyName},</if>"
			+ "<if test=\"companyUrl != null\">company_url = #{companyUrl},</if>"
			+ "<if test=\"merchantName != null\">merchant_name = #{merchantName},</if>"
			+ "<if test=\"account != null\">account = #{account},</if>"
			+ "<if test=\"estimPrice != null\">estim_price = #{estimPrice},</if>"
			+ "<if test=\"actualPrice != null\">actual_price = #{actualPrice},</if>"
			+ "<if test=\"updateBy != null\">update_by = #{updateBy},</if>"
			+ "<if test=\"updateTime != null\">update_time = #{updateTime},</if>"
			+ "</trim>"
			+ "where id = #{id}</script>")
	public int updateCompany(Company tCompany);

	/**
	 * 删除公司
	 * 
	 * @param id 公司主键
	 * @return 结果
	 */
	@Update("update t_company set del_flag = 1 where id = #{id}")
	public int deleteCompanyById(Long id);

	/**
	 * 批量删除公司
	 * 
	 * @param ids 需要删除的数据主键集合
	 * @return 结果
	 */
	@Update("<script>" + "update t_company set del_flag = 1 where id in "
			+ "<foreach item='id' collection='array' open='(' separator=',' close=')'>" + "#{id}" + "</foreach>"
			+ "</script>")
	public int deleteCompanyByIds(String[] ids);

	@Select("select id, project_id, company_name, company_url, merchant_name, account, estim_price, actual_price from t_company where del_flag = 0")
	public List<Company> selectCompanyAll();
}